package lyc.springcloud.admin.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import lyc.springcloud.admin.service.def.IndexService;
import lyc.springcloud.admin.utils.CommonResClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
@Slf4j
public class IndexController {
    @Autowired
    private IndexService indexService;

    /**
     * 获取当前权限下所有menu
     * */
    @PostMapping("/selectMenuTreeById")
    protected CommonResClass selectMenuTreeById(@RequestBody String params) {
        try {
            String userId = (String) JSON.parseObject(params).get("userId");
            List<Map> list = indexService.selectMenuTreeById(userId);
            return CommonResClass.success(list);
        } catch (Exception e) {
            log.error("index页菜单查询失败", e);
            return CommonResClass.failure();
        }
    }
}
